Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch errors on platform #573

Merged
merged 3 commits into from
Jun 4, 2018
Merged

catch errors on platform #573

merged 3 commits into from
Jun 4, 2018

Conversation

ggruiz
Copy link
Contributor

@ggruiz ggruiz commented Jun 4, 2018

Summary

This commit is solely to catch platform errors upon receiving a 200 request that is actually not ok. Test is also included.

Requirements (place an x in each [ ])

@codecov
Copy link

codecov bot commented Jun 4, 2018

Codecov Report

Merging #573 into master will increase coverage by 0.91%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #573      +/-   ##
==========================================
+ Coverage   85.86%   86.78%   +0.91%     
==========================================
  Files           6        6              
  Lines         276      280       +4     
  Branches       42       43       +1     
==========================================
+ Hits          237      243       +6     
+ Misses         27       26       -1     
+ Partials       12       11       -1
Impacted Files Coverage Δ
src/WebClient.ts 93.87% <100%> (+1.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d8a115...f10a0f8. Read the comment docs.

@@ -191,6 +191,19 @@ describe('WebClient', function () {
});
});

it('should return platform error if 200 request is not ok', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rephrase the description of this test case a bit? how about should fail with platform errors when the API response is an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rephrased

return client.apiCall('method')
.catch((error) => {
assert.propertyVal(error, 'code', 'slackclient_platform_error');
assert.propertyVal(error.data, 'ok', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this works since you have indirectly checked the truthiness of error in the preceding line. but i think this ca be improved as assert.nestedPropertyVal(error, 'data.ok', false); since then the order of the assertions wouldn't be significant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken care of in latest commit; changed line 202 to assert.nestedPropertyVal

it('should return platform error if 200 request is not ok', function () {
const scope = nock('https://slack.com')
.post(/api/)
.reply(200, { ok: false });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this response isn't sufficient to test the code. there should be an error property in the response, the way the actual API would provide one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken care of in latest commit; added the property error: 'bad error' to line 197's test response object

.catch((error) => {
assert.propertyVal(error, 'code', 'slackclient_platform_error');
assert.propertyVal(error.data, 'ok', false);
scope.done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're missing an assertion on error.data.error, which should be equal to the error property in the response (as commented above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taken care of in latest commit; along with error: 'bad error' to line 197, also added assert.nestedPropertyVal(error, 'data.error', 'bad error') to inner function of the catch

@@ -191,15 +191,16 @@ describe('WebClient', function () {
});
});

it('should return platform error if 200 request is not ok', function () {
it.only('should fail with platform errors when the API response is an error', function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, lets get rid of this .only()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops

@ggruiz ggruiz merged commit 24488bb into slackapi:master Jun 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants